#define _CRT_SECURE_NO_WARNINGS 1
#include "Stack.h"
Stack::Stack(int capacity)
	:_arr(nullptr)
	, _size(0)
	, _capacity(capacity)
{
	STDateType* newArr = (STDateType*)malloc(sizeof(STDateType) * _capacity);
	if (newArr == nullptr)
	{
		perror("Stack::malloc error\n");
		return;
	}
	_arr = newArr;
}
Stack::~Stack()
{
	if (_arr != nullptr)
	{
		free(_arr);
		_arr = nullptr;
	}
	_capacity = _size = 0;
}
void Stack::Push(STDateType index)
{
	if (_size == _capacity)
	{
		int newCapacity = 2 * _capacity;
		STDateType* newArr = (STDateType*)realloc(_arr, sizeof(STDateType)* newCapacity);
		if (newArr == nullptr)
		{
			perror("Pop::realloc error!\n");
			return;
		}
		_capacity = newCapacity;
		_arr = newArr;
	}
	*(_arr + _size++) = index;
}
void Stack::Pop()
{
	_size--;
}
STDateType& Stack::Top()
{
	return*(_arr + _size - 1);
}
bool Stack::Empty()
{
	return !_size;
}
int Stack::Size()
{
	return _size;
}
